from typing import *

from math import inf
class Solution:

    def minTrioDegree(self, n: int, edges: List[List[int]]) -> int:
        nexts = [[] for _ in range(n + 1)]
        cnts = [0] * (n + 1)
        for u, v in edges:
            nexts[u].append(v)
            nexts[v].append(u)
            cnts[u]+=1
            cnts[v] += 1
        
        ans = inf
        for u,v in edges:
            for e in nexts[u]:
                if e in nexts[v]:
                    ans = min(ans,cnts[u] + cnts[v] + cnts[e])
        return ans - 6 if ans != inf else -1
    
s = Solution()
print(s.minTrioDegree(3,[[3,2],[2,1]]))